<template>
  <el-dialog title="详情" :close-on-click-modal="false" :visible.sync="visible" ref="myDialog"
    class="JNPF-dialog JNPF-dialog_center" lock-scroll width="60%" :modal-append-to-body="false" append-to-body>
    <el-form :model="form" ref="formData" label-position="top" label-width="80px">
        
        <el-form-item label="">
          <div v-for="(item,index) in showData" :key="index">{{ item.name }} {{ item.value }}</div>
        </el-form-item>
        
        <el-form-item label="" v-for="(item,index) in tableData" :key="index">
          <el-divider></el-divider>
          <div v-if="showField.includes('name_ch')">企业全称：{{ item.name_ch }}</div>
          <div v-if="showField.includes('declare_category')">申报类别：{{ item.declare_category }}</div>
          <div v-if="showField.includes('unit_name')">推荐单位：{{ item.unit_name }}</div>
          <div v-if="showField.includes('recommend_reason')">推荐理由：{{ item.recommend_reason }}</div>
          <div v-if="showField.includes('attachment_name')">相关附件：<el-link type="primary" style="cursor:pointer"><a :href="item.attachment_url" target="_blank" download>{{ item.attachment_name }}</a></el-link></div>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleBtnClose">确定</el-button>
      </div>
  </el-dialog>
</template>

<script>
import request from '@/utils/request'
import { deepClone } from '@/utils'
export default {
  data() {
    return {
      visible: false,
      modelId:'',
      sendFunc:()=>{},
      form: {},
      tableData: [],
      currentData: {},
      showData: [],
      showField: [],
    };
  },
  methods: {
    init(modelId,data) {
      console.log('初始化数据',data)
      let {currentData,sendFunc,showData, showField, infoApi} = data
      debugger
      if(!modelId){
        this.$message({
          type: 'error',
          message: '参数传入错误，请与系统管理员联系！',
          duration: 1500,
        })
        return
      }
      if (!sendFunc||typeof sendFunc != 'function') {
        this.$message({
          type: 'error',
          message: '参数传入错误2，请与系统管理员联系！',
          duration: 1500,
        })
        return
      }
      this.sendFunc = sendFunc
      this.modelId = modelId
      this.currentData = currentData
      this.showData = showData
      this.showField = showField

      this.visible = true


      let apiUrl = infoApi
      let params = {...currentData}
      request(
      {
        url: apiUrl,
        method: 'get',
        data:params
      }).then(tableRes => {
        console.log('tableRes', tableRes);
        this.tableData = tableRes.data
      }).catch(res2=>{
      })

    },
    handleBtnClose(){
        // 重置表单数据
        this.$refs.formData.resetFields();
        this.visible = false;
        this.$emit('refreshDataList', true)
    },
    handleClose() {
      // 重置表单数据
      this.$refs.formData.resetFields();
      this.visible = false;
      this.$emit('refreshDataList', true)
    },
    handleSubmit() {
      this.sendFunc({},res1=>{
        this.handleClose();
      })
    },
  }
};
</script>
<style lang="scss" scoped>

</style>